﻿package start
{
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	
	public class StartLoading extends Sprite
	{	
		[Embed(source= "loadingFace.png")]
		public static var Bar:Class;
		
		[Embed(source= "loadingBg.png")]
		public static var BarBg:Class;
		
		private var face:DisplayObject;
		private var bg:DisplayObject;
		private var faceM:Shape;
		private var _percent:Number;
		
		private var textField:TextField;
		
		public function StartLoading()
		{
			initImg();
			initMask();
			initTextField();
			percent = 0;
		}
		
		private function initTextField():void
		{
			textField = new TextField();
			textField.width = face.width;
			textField.height = 20;
			textField.y = face.y - 20;
			textField.x = face.x;
			
			var tf:TextFormat = new TextFormat();
			tf.size = 12;
			tf.color = 0xFFFFFF;
			tf.align = TextFormatAlign.CENTER;
			tf.font = "Arial";
			
			textField.defaultTextFormat = tf;
			
			addChild(textField);
		}
		
		private function initMask():void
		{
			faceM = new Shape();
			addChild(faceM);
			with(faceM.graphics)
			{
				beginFill(0);
				drawRect(face.x,face.y,face.width,face.height);01
				endFill();
			}
			face.mask = faceM;
		}
		
		private function initImg():void
		{
			face = new Bar();
			bg = new BarBg();
			addChild(bg);
			addChild(face);
		}
		
		public function set text(v:String):void
		{
			textField.text = v;
		}
		
		public function set percent(v:Number):void
		{
			faceM.width = face.width * v;
		}
		
		public function set logo(v:DisplayObject):void
		{
			v.x = 100;
			v.y = 50;
			addChild(v);
		}
		
		
	}
}